<!DOCTYPE html>
<html lang="en" class="light">

<head>
  <meta charset="UTF-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Document</title>
  <style>
    :root {
      --primary-color: #fff;
      --second-color: #111;
    }

    * {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }

    html {
      transition: all 0.3s ease-in;
    }

    html.dark {
      --primary-color: #111;
      --second-color: #fff;
      background-color: var(--primary-color);
      color: var(--second-color);
    }

    body {
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      height: 100vh;
    }

    .toggle {
      position: absolute;
      top: 120px;
      padding: 10px;
      border-radius: 5px;
      border: none;
      background-color: var(--second-color);
      color: var(--primary-color);
    }

    .clock {
      position: relative;
      width: 250px;
      height: 250px;
    }

    .hour {
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -100%) rotate(20deg);
      width: 3px;
      height: 70px;
      background-color: var(--second-color);
      transform-origin: bottom center;
    }

    .minute {
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -100%) rotate(30deg);
      width: 3px;
      height: 90px;
      background-color: var(--second-color);
      transform-origin: bottom center;
    }

    .second {
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -100%) rotate(0deg);
      width: 3px;
      height: 130px;
      background-color: red;
      transform-origin: bottom center;
    }

    .center-point {
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%) rotate(0deg);
      width: 10px;
      height: 10px;
      border-radius: 50%;
      /* border:1px solid red; */
      background-color: var(--second-color);
    }

    .timeWrap {
      margin-top: 50px;
    }

    .timeWrap .time {
      font-size: 35px;
    }

    .timeWrap .date {
      text-align: center;
    }

    .datespan {
      display: inline-block;
      width: 20px;
      height: 20px;
      line-height: 20px;
      background-color: var(--second-color);
      color: var(--primary-color);
      border-radius: 50%;
      font-size: 13px;
    }
  </style>
</head>

<body>
  <button class="toggle">Light Mode</button>
  <div class="clock">
    <div class="hour"></div>
    <div class="minute"></div>
    <div class="second"></div>
    <div class="center-point"></div>
  </div>
  <div class="timeWrap">
    <p class="time">1:43 PM</p>
    <p class="date">Sun,May <span class="datespan">9</span></p>
  </div>
</body>
<script>
  let toggle = document.querySelector('.toggle');
  let html = document.querySelector('html');
  toggle.addEventListener('click', () => {
    if (html.classList.contains('dark')) {
      toggle.textContent = 'Light Mode';
    } else {
      toggle.textContent = 'Dark Mode';
    }
    html.classList.toggle('dark');
  });

  function getTime() {
    let date = new Date();
    let hour = date.getHours();
    let minute = date.getMinutes();
    let second = date.getSeconds();
    let dates = date.getDate();
    let hourEl = document.querySelector('.hour');
    let minuteEl = document.querySelector('.minute');
    let secondEl = document.querySelector('.second');
    let timeEl = document.querySelector('.time');
    let dateEl = document.querySelector('.date');
    let ampm = hour > 12 ? 'PM' : 'AM';
    timeEl.textContent = `${hour % 12}:${minute} ${ampm}`;
    let dateStr = new Date().toDateString().split(' ');
    let [weekday, month] = dateStr;
    dateEl.innerHTML = `${weekday},${month} <span class="datespan">${dates}</span> `
    hourEl.style.transform = ` translate(-50%, -100%) rotate(${(hour / 12) * 360
      }deg)`;
    minuteEl.style.transform = ` translate(-50%, -100%) rotate(${(minute / 60) * 360
      }deg)`;
    secondEl.style.transform = ` translate(-50%, -100%) rotate(${(second / 60) * 360
      }deg)`;
    console.log(hour / 12 * 360)
  }
  getTime();
  setInterval(() => {
    getTime();
  }, 1000);
</script>

</html>